using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using SCS.Common.Models;
namespace SCS.DAL.Mapping
{
    public class LearnerMap : EntityTypeConfiguration<Learner>
    {
        public LearnerMap()
        {
            // Primary Key
            this.HasKey(t => t.learnerID);

            // Properties
            this.Property(t => t.learnerID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.firstName)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.lastName)
                .IsRequired()
                .HasMaxLength(20);

            this.Property(t => t.gender)
                .IsRequired()
                .IsFixedLength()
                .HasMaxLength(1);

            this.Property(t => t.birthPlace)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.address)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("Learners");
            this.Property(t => t.learnerID).HasColumnName("learnerID");
            this.Property(t => t.firstName).HasColumnName("firstName");
            this.Property(t => t.lastName).HasColumnName("lastName");
            this.Property(t => t.dateOfBirth).HasColumnName("dateOfBirth");
            this.Property(t => t.gender).HasColumnName("gender");
            this.Property(t => t.birthPlace).HasColumnName("birthPlace");
            this.Property(t => t.parentID).HasColumnName("parentID");
            this.Property(t => t.address).HasColumnName("address");
            this.Property(t => t.classID).HasColumnName("classID");
            this.Property(t => t.deactive).HasColumnName("deactive");

            // Relationships
            this.HasOptional(t => t.Class)
                .WithMany(t => t.Learners)
                .HasForeignKey(d => d.classID);
            this.HasOptional(t => t.Parent)
                .WithMany(t => t.Learners)
                .HasForeignKey(d => d.parentID);

        }
    }
}
